import http from '@/utils/http'

const module = {
  namespaced: true,
  state: {
    cinemaList: []
  },
  mutations: {
    setCinemaList(state, list) {
      state.cinemaList = list
    },
    clearCinemaList(state) { // 状态容易跟踪
      state.cinemaList = []
    }
  },
  actions: {
    getCinemaList({commit}, cityId) {
    //   return http({
    //       url: `/gateway?cityId=${cityId}&ticketFlag=1&k=4127869`,
    //       headers: {
    //         'X-Host': 'mall.film-ticket.cinema.list'
    //       }
    //     }).then((response) => {
    //       console.log(response)
    //       let res = response.data
    //       if (res.status === 0) {
    //         let data = res.data
    //         commit('setCinemaList', data.cinemas)
    //       }
    //     }).catch(error => {
    //     })
    // }
      return new Promise((resolve, reject) => {
        http({
          url: `/gateway?cityId=${cityId}&ticketFlag=1&k=4127869`,
          headers: {
            'X-Host': 'mall.film-ticket.cinema.list'
          }
        }).then((response) => {
          console.log(response)
          let res = response.data
          if (res.status === 0) {
            let data = res.data
            commit('setCinemaList', data.cinemas)
          }
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default module